<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/resources/css/font.css">
    <link rel="stylesheet" href="/resources/css/xadmin.css">
    <script type="text/javascript" src="/resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/resources/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]--></head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <!-- @formatter:off -->
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="id" class="layui-form-label">客户编号</label>
                <div class="layui-input-block"><input type="text" id="id" name="id" disabled lay-verify="required" autocomplete="on" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label"><span class="x-red">*</span>客户名称</label>
                <div class="layui-input-inline"><input type="text" id="name" name="name" required lay-verify="required" autocomplete="on" class="layui-input"></div>
                <label for="fullName" class="layui-form-label"><span class="x-red">*</span>客户全称</label>
                <div class="layui-input-inline"><input type="text" id="fullName" name="fullName" required lay-verify="required" autocomplete="on" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="address" class="layui-form-label"><span class="x-red">*</span>地址</label>
                <div class="layui-input-inline"><input type="text" id="address" name="address" required lay-verify="required" autocomplete="on" class="layui-input"></div>
                <label for="fax" class="layui-form-label"><span class="x-red">*</span>传真</label>
                <div class="layui-input-inline"><input type="text" id="fax" name="fax" required lay-verify="required" autocomplete="on" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="mail" class="layui-form-label"><span class="x-red">*</span>邮箱</label>
                <div class="layui-input-inline"><input type="text" id="mail" name="mail" required autocomplete="on" class="layui-input"></div>
                <label for="manager" class="layui-form-label"><span class="x-red">*</span>经理姓名</label>
                <div class="layui-input-inline"><input type="text" id="manager" name="manager" required autocomplete="on" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label"><span class="x-red">*</span>联系电话</label>
                <div class="layui-input-inline"><input type="text" id="phone" name="phone" required autocomplete="on" class="layui-input"></div>
                <label for="status" class="layui-form-label"><span class="x-red">*</span>客户状态</label>
                <div class="layui-input-inline">
                    <select id="status" name="status" class="valid">
                        <option value="">请选择</option>
                        <option value="有效">有效</option>
                        <option value="无效">无效</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="introduce" class="layui-form-label">客户介绍</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="introduce" name="introduce" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
            </div>
        </form>
    </div>
</div>
</body>
<!-- @formatter:on -->
<script>
    // 北京时间：2021-11-18 22:14:24
    /* 时间yyyy-MM-dd HH:mm:ss转为时间戳 */
    function timeToTimestamp(time) {
        let timestamp = Date.parse(new Date(time).toString());
        //timestamp = timestamp / 1000; //时间戳为13位需除1000，时间戳为13位的话不需除1000
        console.log(time + "的时间戳为：" + timestamp);
        return timestamp;
        //2021-11-18 22:14:24的时间戳为：1637244864707
    }

    // 时间戳：1637244864707
    /* 时间戳转换为时间 */
    function timestampToTime(timestamp) {
        timestamp = timestamp ? timestamp : null;
        let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        let Y = date.getFullYear() + '-';
        let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
        let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        return Y + M + D + h + m + s;
    }

    let customerData = JSON.parse(sessionStorage.getItem("editData"));

    document.getElementById("id").value = customerData.id
    document.getElementById("name").value = customerData.name;
    document.getElementById("fullName").value = customerData.fullName;
    document.getElementById("address").value = customerData.address;
    document.getElementById("fax").value = customerData.fax;
    document.getElementById("mail").value = customerData.mail;
    document.getElementById("manager").value = customerData.manager;
    document.getElementById("phone").value = customerData.phone;
    document.getElementById("status").value = customerData.status;
    document.getElementById("introduce").value = customerData.introduce;


    layui.use(function () {
        $ = layui.jquery;
        let form = layui.form;
        let layer = layui.layer;
        let table = layui.table;

        //自定义验证规则
        form.verify({});

        //监听提交
        form.on('submit(edit)',
            function (data) {

                //数据提交后端
                $.ajax({
                    url: "/plan/customerModify",
                    type: "post",
                    data: JSON.stringify(data.field),
                    //不要处理数据
                    processData: false,
                    //不要设置content-type请求头
                    contentType: "application/json",
                    success: function (res) {
                        if (res.code == 200) {
                            layer.alert("修改成功", {icon: 6},
                                function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    // xadmin.close();
                                    // xadmin.father_reload();
                                });
                        } else {
                            layer.alert("修改失败", {icon: 6})
                        }
                    }
                })
                return false;
            });

        //重新渲染表格方法
        window.reload = function () {
            // 重新渲染表格
            table.reloadData('customerTable', {
                // 设定重载数据或切换分页时的滚动条的位置状态
                scrollPos: true,
            });
        }
    });
</script>

</html>